package com.kgis.fm.common.manager
{
	import com.kgis.fm.flex.model.term.BusinessLabel;
	import com.kgis.fm.flex.model.term.BusinessLabelRule;
	import com.kgis.fm.flex.model.term.LegendEntry;
	import com.kgis.map.Map;
	import com.kgis.map.rule.Rule;
	import com.kgis.map.style.StyleRule;
	
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;

	/**
	 * LabelRule构造器
	 * */
	public class LabelRuleManager
	{
		public function LabelRuleManager()
		{
		}

		public static function getLabelRule(legendEntry:LegendEntry):Rule
		{
			if(!legendEntry){
				return null;
			}
			var labelRuleList:ArrayCollection=MetaDataManager.getLabelRuleByLegendEntryId(legendEntry.lrno);
			var result:Rule=null;
			for each (var businessLabelRule:BusinessLabelRule in labelRuleList)
			{
				//查找标注
				var businessLabel:BusinessLabel=MetaDataManager.getLabelById(businessLabelRule.lfno) as BusinessLabel;
				if(businessLabel){
					var strLabel:String=businessLabel.content;
					if (!result)
					{
						result=new Rule();
						var ruleDictionary:ArrayCollection=new ArrayCollection();
						result.expressionFilterDic=ruleDictionary;
					}
					
					var sr:StyleRule=new StyleRule();
					if (!businessLabelRule.filter)
					{
						sr.filter="1==1";
					}
					else
					{
						sr.filter=businessLabelRule.filter;
					}
					sr.label=strLabel;
					ruleDictionary.addItem(sr);
				}
				
			}
			return result;
		}

	}
}